-- Decompiled with the Synapse X Luau decompiler.

local v1 = {
	__mode = "kv"
};

function v1.__index(p1, p2)
	local v2 = {
		__mode = "kv"
	};
	function v2.__index(p3, p4)
		
		--if p2 ~= "" then
		--	--local v3 = "%s.%s";
		--else
		--	v3 = "%s%s";
		--end;
		
		local v3 = "%s%s";
		if p2 ~= "" then
			v3 = "%s.%s";
		end
		
		local v4 = string.format(v3, p2, p4);
		p3[p4] = v4;
		return v4;
	end;
	local v5 = setmetatable({}, v2);
	p1[p2] = v5;
	return v5;
end;
local function u3(p5)
	if p5.__father == false then
		return true;
	end;
	local l____changes__6 = p5.__father.__changes;
	if l____changes__6 and l____changes__6[p5.__key] ~= nil then
		return false;
	end;
	return u3(p5.__father);
end;

local CommonOHOH = _G.CommonOHOH;

--判断数据合法性
local function DataAssert(key, value)

	if type(key) ~= "string" and type(key) ~= "number" then --key只能为字符串或者数字
		error("proxy node: key\229\191\133\233\161\187\230\152\175string or number");
	end;
	if type(key) == "string" then
		if key == "" then --空字符串不能作为key
			error("proxy node: \231\169\186\229\173\151\231\172\166\228\184\178\228\184\141\232\131\189\228\189\156\228\184\186key");
		end;
		if string.find(key, "%s") then -- key包含空白字符
			error("proxy node: key\229\140\133\229\144\171\231\169\186\231\153\189\229\173\151\231\172\166");
		end;
	end;
	if not value then
		return
	end
	local valueTaype = type(value);
	local v8 = false;
	-- if valueTaype ~= "userdata" then
	-- 	v8 = false;
	-- 	if valueTaype ~= "thread" then
	-- 		v8 = valueTaype ~= "function";
	-- 	end;
	-- end;

	if valueTaype =="table" or valueTaype =="string" or valueTaype =="boolean" or valueTaype =="number" then
		 v8 = true;
	end;
		

	assert(v8, "proxy node: value\229\191\133\233\161\187\230\152\175string or number or table or boolean");
	if valueTaype == "table" then
		--带有元表的表不可用于赋值
		assert(not getmetatable(value), "proxy node: \229\184\166\230\156\137\229\133\131\232\161\168\231\154\132\232\161\168\228\184\141\229\143\175\231\148\168\228\186\142\232\181\139\229\128\188");
		-- for v9, v10 in next, value do
		-- 	DataAssert(v9, v10);
		-- end;
		for k,v in pairs(value) do
			DataAssert(k, v);
		end
	end;
end;
local u13 = {};
local function u14(p8, p9)
	p9 = next(p8.__real, p9);
	return p9, p8[p9];
end;
local function PairsFuc(p10, p11)
	if not p11 then
		return u14, p10, nil;
	end;
	return next, p10.__real, nil;
end;
local function u16(p12, p13)
	for v11, v12 in next, p12 do
		if v12 == u13 then
			v12 = nil;
		end;
		p13[v11] = v12;
	end;
end;
local function u17(p14)
	local v13 = {};
	while p14.__father do
		table.insert(v13, 1, p14.__key);
		p14 = p14.__father;	
	end;
	return table.concat(v13, ".");
end;
local function u18(p15, p16)
	if type(p16) ~= "table" then
		return string.format("%s = %s", p15, tostring(p16));
	end;
	return string.format("[%s] = %s", p15, CommonOHOH.dump(p16, false, 16));
end;
local u19 = setmetatable({}, v1);
local function RefFuc(self)
	local l____cached__14 = self.__cached;
	local v15 = self;
	while v15 do
		l____cached__14[v15.__real] = v15;
		v15 = v15.__father;	
	end;
	return self;
end;
local function UnrefFuc(p18)
	p18.__cached[p18.__real] = nil;
end;
local function IpairsFuc(p19, p20)
	return PairsFuc(p19, p20);
end;
local function LenFuc(self)
	return #self.__real;
end;
local function IsdirtyFuc(self)
	return self.__dirty.yes;
end;
local function CleanFuc(self)
	self.__dirty.yes = false;
end;
local function RevertFuc(self)
	for v16, v17 in next, self.__accessed do
		local l____changes__18 = v17.__changes;
		if l____changes__18 then
			u16(l____changes__18, v16);
			v17.__changes = false;
		end;
		self.__accessed[v16] = nil;
	end;
end;
local function UpdateFuc(self)
	local l____accessed__19 = self.__accessed;
	for v20, v21 in next, l____accessed__19 do
		v21.__changes = false;
		l____accessed__19[v20] = nil;
	end;
end;
local function LogFuc(self)
	local v22 = {};
	for v23, v24 in next, self.__accessed do
		local l____changes__25 = v24.__changes;
		if l____changes__25 and u3(v24) then
			local v26 = u17(v24);
			local l____real__27 = v24.__real;
			for v28, v29 in next, l____changes__25 do
				table.insert(v22, u18(u19[v26][v28], l____real__27[v28]));
			end;
		end;
	end;
	if not (#v22 > 0) then
		return;
	end;
	return table.concat(v22, "\n");
end;
local MT = {};
--sourceData, false, "", {}, {}, {}
local function init(real, father, key, cached, accessed, dirty)
	return setmetatable({
		__father = father, 
		__key = key, 
		__real = real, 
		__cached = cached, 
		__accessed = accessed, --[self.__real[k]]=self
		__dirty = dirty, 
		__changes = false, 
		Ref = RefFuc, 
		Unref = UnrefFuc, 
		Pairs = PairsFuc, 
		Ipairs = IpairsFuc, 
		Len = LenFuc, 
		Isdirty = IsdirtyFuc, 
		Clean = CleanFuc, 
		Revert = RevertFuc, 
		Update = UpdateFuc, 
		Log = LogFuc
	}, MT);
end;
-- 查询
function MT.__index(self, kid)
	local value = self.__real[kid];
	if type(value) ~= "table" then
		return value;
	end;
	local subTable = self.__accessed[value] or self.__cached[value];
	if not subTable then
		subTable = init(value, self, kid, self.__cached, self.__accessed, self.__dirty);
		self.__accessed[value] = subTable;
	end;
	return subTable;
end;
--赋值
function MT.__newindex(self, key, value)
	DataAssert(key, value);
	local change = self.__changes;
	if not change then
		change = {};
		self.__changes = change;
		self.__accessed[self.__real] = self;
		self.__dirty.yes = true;
	end;
	if change[key] == nil then
		local v34 = self.__real[key];
		if v34 == nil then
			v34 = u13;
		end;
		change[key] = v34;
	end;
	self.__real[key] = value;
end;
local v35 = {
	Ref = function(p38)

	end, 
	Update = function(p39)

	end, 
	Unref = function(p40)

	end, 
	Pairs = function(p41, p42)

	end, 
	Ipairs = function(p43, p44)

	end, 
	Len = function(p45)

	end, 
	Isdirty = function(p46)

	end, 
	Clean = function(p47)

	end, 
	Revert = function(p48)

	end, 
	Log = function(p49)

	end
};
return {
	new = function(real)
		--real, father, key, cached, accessed, dirty
		return init(real, false, "", {}, {}, {});
	end
};
